//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.moons.settings.config;

import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.Keep;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

@Keep
public class ARUsbTransfer {
    private static final String TAG = ARUsbTransfer.class.getSimpleName();
    private static final boolean SHOWLOG = false;
    private static final String ACTION_USB_PERMISSION = "cn.artosyn.artosynuvctest3.USB_PERMISSION";
    private PendingIntent mPermissionIntent;
    private UsbManager mUsbManager;
    private UsbDevice mUsbDevice;
    private WeakReference<Context> mWeakContext = null;
    private static final int USB_DEV_VID = 7531;
    private static final int USB_DEV_PID = 258;
    private ARHidDevHelper mHIDHelper;
    private ARUsbTransfer.TransThread transThread = null;
    private ARUsbTransfer.ReadThread readThread = null;
    private static final int HID_TRANS_STATUS = 2;
    private static final int HID_TRANS_PROGRESS = 3;
    private static final int HID_UPGRADE_STATUS = 4;
    private static final int HID_UCMD_RET = 5;
    private final int USB_OUT_PACKET_SIZE = 1024;
    private final int MTU_HEADER_LEN = 36;
    private final int MTU_PAYLOAD_LEN = 988;
    private byte[] MTU_MAGIC = new byte[]{-1, 85, -1, -86, 65, 82, 84, 79};
    private final int USB_IN_PACKET_SIZE = 512;
    private final int MTU_PAYLOAS_LEN_IN = 476;
    private final int HID_HEADER_LEN = 12;
    private final short HID_PORT_UCMD = 3;
    private final byte[] ucmd_flag = new byte[]{117, 99, 109, 100};
    private final short HID_PORT_GIFO = 8;
    private final byte[] gifo_flag = new byte[]{103, 105, 102, 111};
    private final short HID_PORT_HERT = 9;
    private final byte[] hert_flag = new byte[]{104, 101, 114, 116};
    public static final byte HERT_START = 1;
    public static final byte HERT_STOP = 0;
    public static final byte HERT_INFO = 2;
    public static final byte HERT_REBOOT = 3;
    private final short HID_PORT_CONF = 10;
    private final byte[] conf_flag = new byte[]{99, 111, 110, 102};
    private ARUsbTransfer.StatusCallback statusCallback = null;
    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if ("cn.artosyn.artosynuvctest3.USB_PERMISSION".equals(action)) {
                synchronized(this) {
                    UsbDevice device = (UsbDevice)intent.getParcelableExtra("device");
                    if (intent.getBooleanExtra("permission", false)) {
                        if (device != null) {
                            ARUsbTransfer.this.mUsbDevice = device;
                            if (ARUsbTransfer.this.mHIDHelper.OpenDevice(ARUsbTransfer.this.mUsbManager, ARUsbTransfer.this.mUsbDevice)) {
                                Log.d(ARUsbTransfer.TAG, "Open usb success");
                                ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_OPEN_STATUS, "Open usb success", 0);
                                ARUsbTransfer.this.readThread = ARUsbTransfer.this.new ReadThread();
                                ARUsbTransfer.this.readThread.Start();
                            } else {
                                Log.d(ARUsbTransfer.TAG, "Open usb failed");
                                ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_OPEN_STATUS, "Open usb failed", 0);
                            }
                        }
                    } else {
                        Log.d(ARUsbTransfer.TAG, "permission denied for device " + device);
                        ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_OPEN_STATUS, "Permission denied for usb device", 0);
                    }
                }
            }

        }
    };

    public void addCallback(ARUsbTransfer.StatusCallback callback) {
        this.statusCallback = callback;
    }

    public void removeCallback() {
        this.statusCallback = null;
    }

    private void statusChange(ARUsbTransfer.LOG_MSG_TYPE msg_type, String msg, int process) {
        if (this.statusCallback != null) {
            this.statusCallback.onStatusChange(msg_type, msg, process);
        }
    }

    public ARUsbTransfer(Context ctx) {
        this.mWeakContext = new WeakReference(ctx);
        this.mHIDHelper = new ARHidDevHelper();
        this.transThread = new ARUsbTransfer.TransThread();
    }

    public void register() {
        Context context = (Context)this.mWeakContext.get();
        this.mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent("cn.artosyn.artosynuvctest3.USB_PERMISSION"), 0);
        IntentFilter filter = new IntentFilter("cn.artosyn.artosynuvctest3.USB_PERMISSION");
        context.registerReceiver(this.mUsbReceiver, filter);
        Log.i(TAG, "*************************************register receiver");
        this.mUsbManager = (UsbManager)context.getSystemService("usb");
    }

    public void unregister() {
        Log.i(TAG, "*************************************unregister receiver");
        Context context = (Context)this.mWeakContext.get();
        context.unregisterReceiver(this.mUsbReceiver);
    }

    boolean updateArUvc() {
        UsbManager usbManager = (UsbManager)((Context)this.mWeakContext.get()).getSystemService("usb");
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        Iterator deviceIterator = deviceList.values().iterator();

        UsbDevice dev;
        do {
            if (!deviceIterator.hasNext()) {
                return false;
            }

            dev = (UsbDevice)deviceIterator.next();
        } while(dev.getVendorId() != 7531 || dev.getProductId() != 258);

        this.mUsbDevice = dev;
        Log.i(TAG, String.format("Get target usb device %4x %4x", dev.getVendorId(), dev.getProductId()));
        return true;
    }

    public static boolean hasArUvc(Context ctx) {
        UsbManager usbManager = (UsbManager)ctx.getSystemService("usb");
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        Iterator deviceIterator = deviceList.values().iterator();

        UsbDevice dev;
        do {
            if (!deviceIterator.hasNext()) {
                return false;
            }

            dev = (UsbDevice)deviceIterator.next();
        } while(dev.getVendorId() != 7531 || dev.getProductId() != 258);

        Log.i(TAG, String.format("Get target usb device %4x %4x", dev.getVendorId(), dev.getProductId()));
        return true;
    }

    public boolean Open() {
        if (!this.updateArUvc()) {
            return false;
        } else {
            if (this.mUsbManager.hasPermission(this.mUsbDevice) && this.mHIDHelper.OpenDevice(this.mUsbManager, this.mUsbDevice)) {
                Log.d(TAG, "Open usb success");
                this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_OPEN_STATUS, "Open usb success", 0);
                this.readThread = new ARUsbTransfer.ReadThread();
                this.readThread.Start();
            } else {
                Log.d(TAG, "Open usb fail,need to request permission");
                this.mUsbManager.requestPermission(this.mUsbDevice, this.mPermissionIntent);
            }

            Log.d(TAG, "Open return true");
            return true;
        }
    }

    public void Close() {
        if (this.readThread != null) {
            this.readThread.Stop();
        }

        this.mHIDHelper.CloseDevice();
    }

    public void TransFirmware(String filename) {
        if (!this.mHIDHelper.isOpend()) {
            this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_TRANS_STATUS, "No opened usb device", 0);
        } else {
            this.Trans(0, filename);
        }
    }

    public void TransFile(String filename) {
        if (!this.mHIDHelper.isOpend()) {
            this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_TRANS_STATUS, "No opened usb device", 0);
        } else {
            this.Trans(1, filename);
        }
    }

    private void Trans(int mode, String filename) {
        this.transThread.mode = mode;
        this.transThread.SetFileName(filename);
        this.transThread.start();
    }

    public boolean SendUCmd(String ucmd) {
        if (ucmd.isEmpty()) {
            return false;
        } else {
            byte[] cumd_data = ucmd.getBytes();
            byte[] hid_payload = new byte[260];
            System.arraycopy(this.ucmd_flag, 0, hid_payload, 0, this.ucmd_flag.length);
            System.arraycopy(cumd_data, 0, hid_payload, 4, cumd_data.length);
            return this.SendHidPacket((short)3, hid_payload);
        }
    }

    public boolean SendReadDevInfoCmd() {
        return this.SendHidPacket((short)8, this.gifo_flag);
    }

    public boolean sendHeartCmd(int data) {
        byte[] hid_payload = new byte[8];
        System.arraycopy(this.hert_flag, 0, hid_payload, 0, this.hert_flag.length);
        ARUtil.int2bytes(hid_payload, 4, data);
        return this.SendHidPacket((short)9, hid_payload);
    }

    public boolean sendArstackConfig(int cmd, byte[] data) {
        byte[] cmd_payload = new byte[12];
        int datalen = data == null ? 0 : data.length;
        System.arraycopy(this.conf_flag, 0, cmd_payload, 0, this.conf_flag.length);
        ARUtil.int2bytes(cmd_payload, 4, cmd);
        ARUtil.int2bytes(cmd_payload, 8, datalen);
        boolean bret = this.SendHidPacket((short)10, cmd_payload);
        Log.d(TAG,"=============bret=="+bret);
        if (!bret) {
            return false;
        } else {
            return data == null ? true : this.SendHidPacket((short)10, data);
        }
    }

    boolean SendHidPacket(short port, byte[] hid_payload) {
        int mtu_pay_len = 12 + hid_payload.length;
        byte[] hid_pkt = new byte[mtu_pay_len];
        Arrays.fill(hid_pkt, (byte)0);
        int hid_data_offset = 0;
        ARUtil.short2bytes(hid_pkt, hid_data_offset, port);
        hid_data_offset = hid_data_offset + 2;
        ARUtil.short2bytes(hid_pkt, hid_data_offset, 12);
        hid_data_offset += 2;
        ARUtil.int2bytes(hid_pkt, hid_data_offset, hid_payload.length);
        hid_data_offset += 4;
        hid_data_offset += 4;
        System.arraycopy(hid_payload, 0, hid_pkt, hid_data_offset, hid_payload.length);
        int var10000 = hid_data_offset + hid_payload.length;
        if (mtu_pay_len > 988) {
        }

        int pkt_num = (mtu_pay_len + 988 - 1) / 988;
        byte[] mtu_pkt = new byte[1024];
        int hid_ptk_offset = 0;
//        int pay_len = false;

        for(int i = 0; i < pkt_num; ++i) {
            Arrays.fill(mtu_pkt, (byte)0);
            int pay_len;
            if (i == pkt_num - 1) {
                pay_len = mtu_pay_len - 988 * (pkt_num - 1);
            } else {
                pay_len = 988;
            }

            System.arraycopy(hid_pkt, hid_ptk_offset, mtu_pkt, 36, pay_len);
            int mtu_data_offset = 0;
            System.arraycopy(this.MTU_MAGIC, 0, mtu_pkt, mtu_data_offset, this.MTU_MAGIC.length);
//            int mtu_data_offset = 0;
            mtu_data_offset = mtu_data_offset + this.MTU_MAGIC.length;
            ARUtil.int2bytes(mtu_pkt, mtu_data_offset, 36);
            mtu_data_offset += 4;
            ARUtil.int2bytes(mtu_pkt, mtu_data_offset, mtu_pay_len);
            mtu_data_offset += 4;
            ARUtil.int2bytes(mtu_pkt, mtu_data_offset, pay_len);
            mtu_data_offset += 4;
            ARUtil.int2bytes(mtu_pkt, mtu_data_offset, pkt_num);
            mtu_data_offset += 4;
            ARUtil.int2bytes(mtu_pkt, mtu_data_offset, i);
            mtu_data_offset += 4;
            mtu_pkt[mtu_data_offset] = 1;
            mtu_data_offset += 4;
            ARUtil.checkSum(mtu_pkt, pay_len, 36, mtu_data_offset);
            int dlen = 36 + pay_len;
            int wlen = this.mHIDHelper.WriteData2(mtu_pkt, dlen, 10);
            if (wlen != dlen) {
                return false;
            }

            hid_ptk_offset += pay_len;
        }

        return true;
    }

    private class TransThread extends Thread {
        public Handler threadHandler;
        public int mode;
        public String mFileName;
        static final int HEADER_LEN = 36;
        static final int PAYLOAD_LEN = 988;
        static final int TOTAL_LEN = 1024;
        private byte[] datapkt = new byte[1024];
        static final int HID_HEADER_LEN = 12;
        private byte[] hidheader;
        int file_offset = 0;
        private byte[] magic = new byte[]{-1, 85, -1, -86, 65, 82, 84, 79, 36, 0, 0, 0};
        private byte[] upgd_flag = new byte[]{117, 112, 103, 100};
        private byte[] file_flag = new byte[]{102, 105, 108, 101};
        private byte[] file_name = new byte[256];
        private String sfilename = "temp.bin\u0000";

        public TransThread() {
            Arrays.fill(this.datapkt, (byte)0);
            System.arraycopy(this.magic, 0, this.datapkt, 0, this.magic.length);
            this.hidheader = new byte[12];
            Arrays.fill(this.hidheader, (byte)0);
            ARUtil.short2bytes(this.hidheader, 2, 12);
            this.datapkt[28] = 1;
        }

        public void SetFileName(String name) {
            this.mFileName = name;
            this.sfilename = this.mFileName + "\u0000";
        }

        private void sendStatus(String str) {
            ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_TRANS_STATUS, str, 0);
        }

        private void sendProgress(int a) {
            ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_TRANS_PROGRESS, "", a);
        }

        public void run() {
            long startTime = System.currentTimeMillis();
            File sdcard = Environment.getExternalStorageDirectory();
            File path = new File(sdcard, this.mFileName);
            if (!path.canRead()) {
                this.sendStatus("Can't read file");
            } else {
                long file_len = path.length();
                if (file_len <= 0L) {
                    this.sendStatus("Can't send empty file");
                } else {
                    long sFram_num = (path.length() + 12L) / 988L;
                    int last_fram_len = (int)(path.length() + 12L) % 988;
                    if (last_fram_len > 0) {
                        ++sFram_num;
                    }

                    Log.i(ARUsbTransfer.TAG, String.format("File size:%d Payload len:%d Frame num:%d Last len:%d", path.length(), 988, sFram_num, last_fram_len));
//                    int rlen = false;
//                    int plen = false;
//                    int wlen = false;
                    int lenoffser = 36;
                    switch(this.mode) {
                        case 0:
                            ARUtil.short2bytes(this.hidheader, 0, 0);
                            ARUtil.int2bytes(this.hidheader, 4, 8);
                            System.arraycopy(this.hidheader, 0, this.datapkt, lenoffser, 12);
                            lenoffser += 12;
                            System.arraycopy(this.upgd_flag, 0, this.datapkt, lenoffser, this.upgd_flag.length);
                            lenoffser += this.upgd_flag.length;
                            ARUtil.int2bytes(this.datapkt, lenoffser, (int)file_len);
                            lenoffser += 4;
                            break;
                        case 1:
                            ARUtil.short2bytes(this.hidheader, 0, 1);
                            ARUtil.int2bytes(this.hidheader, 4, 264);
                            System.arraycopy(this.hidheader, 0, this.datapkt, lenoffser, 12);
                            lenoffser += 12;
                            System.arraycopy(this.file_flag, 0, this.datapkt, lenoffser, this.file_flag.length);
                            lenoffser += this.file_flag.length;
                            ARUtil.int2bytes(this.datapkt, lenoffser, (int)file_len);
                            lenoffser += 4;
                            byte[] filenamearray = this.sfilename.getBytes();
                            System.arraycopy(filenamearray, 0, this.datapkt, lenoffser, filenamearray.length);
                            lenoffser += 256;
                    }

                    ARUtil.checkSum(this.datapkt, lenoffser - 36, 36, 32);
                    ARUtil.int2bytes(this.datapkt, 12, lenoffser - 36);
                    ARUtil.int2bytes(this.datapkt, 20, 1);
                    ARUtil.int2bytes(this.datapkt, 24, 0);
                    int wlenx = ARUsbTransfer.this.mHIDHelper.WriteData2(this.datapkt, lenoffser, 10);
                    Log.i(ARUsbTransfer.TAG, "send file header");
                    if (wlenx != lenoffser) {
                        Log.i(ARUsbTransfer.TAG, "send file len failed.");
                        this.sendStatus("send file len failed.");
                    } else {
                        FileInputStream stream = null;

                        try {
                            stream = new FileInputStream(path);
                        } catch (FileNotFoundException var30) {
                            var30.printStackTrace();
                            this.sendStatus("read file failed:" + var30.getMessage());
                            return;
                        }

                        this.sendStatus("Begin send file");
                        ARUtil.int2bytes(this.datapkt, 12, (int)file_len);
                        ARUtil.int2bytes(this.datapkt, 20, (int)sFram_num);
                        this.file_offset = 0;
                        boolean var15 = true;

                        try {
                            for(int i = 0; (long)i < sFram_num; ++i) {
                                long startTime2 = System.currentTimeMillis();
                                int rlenx;
                                int frlen;
                                if (i == 0) {
                                    ARUtil.int2bytes(this.hidheader, 4, (int)file_len);
                                    System.arraycopy(this.hidheader, 0, this.datapkt, lenoffser, 12);
                                    rlenx = 976;
                                    frlen = stream.read(this.datapkt, 48, rlenx);
                                    if (frlen == -1) {
                                        break;
                                    }
                                } else {
                                    rlenx = 988;
                                    if ((long)i == sFram_num - 1L) {
                                        rlenx = last_fram_len;
                                    }

                                    frlen = stream.read(this.datapkt, 36, rlenx);
                                    if (frlen == -1) {
                                        break;
                                    }
                                }

                                this.file_offset += rlenx;
                                ARUtil.int2bytes(this.datapkt, 16, 988);
                                ARUtil.int2bytes(this.datapkt, 24, i);
                                ARUtil.checkSum(this.datapkt, rlenx, 36, 32);
                                int plenx;
                                if (i == 0) {
                                    plenx = rlenx + 36 + 12;
                                } else {
                                    plenx = rlenx + 36;
                                }

                                wlenx = ARUsbTransfer.this.mHIDHelper.WriteData2(this.datapkt, plenx, 10);
                                long endTime2 = System.currentTimeMillis();
                                Log.i(ARUsbTransfer.TAG, String.format("send data %d/%d %d %d %d %dms offset:%d", i, (int)sFram_num, rlenx, plenx, wlenx, endTime2 - startTime2, this.file_offset));
                                if (wlenx != plenx) {
                                    Log.i(ARUsbTransfer.TAG, "can not send whole data.");
                                    break;
                                }

                                this.sendProgress((int)((double)((float)(i + 1) / (float)sFram_num) * 100.0D));
                            }

                            Log.i(ARUsbTransfer.TAG, "File read end");
                            this.sendStatus("Send file complete");
                        } catch (Exception var31) {
                            var31.printStackTrace();
                        } finally {
                            try {
                                if (stream != null) {
                                    stream.close();
                                }
                            } catch (IOException var29) {
                                var29.printStackTrace();
                            }

                        }

                        long endTime = System.currentTimeMillis();
                        Log.i(ARUsbTransfer.TAG, String.format("time %d-%d=%d ms", endTime, startTime, endTime - startTime));
                    }
                }
            }
        }
    }

    private class ReadThread extends Thread {
        private byte[] mtu_payload_cache;
        private boolean bRun = false;
        private byte[] magic = new byte[]{-1, 85, -1, -86, 65, 82, 84, 79};
        private final ARUsbTransfer.MTU_HEADER mtu_header = ARUsbTransfer.this.new MTU_HEADER();
        private final ARUsbTransfer.HID_HEADER hid_header = ARUsbTransfer.this.new HID_HEADER();

        public ReadThread() {
        }

        void Start() {
            this.bRun = true;
            this.start();
        }

        void Stop() {
            this.bRun = false;
        }

        private ARUsbTransfer.MTU_HEADER get_mtu_header(byte[] data, int offset) {
            System.arraycopy(data, offset, this.mtu_header.magic_number, 0, 8);
            int data_offset = offset + 8;
            this.mtu_header.header_len = ARUtil.bytes2int(data, data_offset);
            data_offset += 4;
            this.mtu_header.total_len = ARUtil.bytes2int(data, data_offset);
            data_offset += 4;
            this.mtu_header.payload_len = ARUtil.bytes2int(data, data_offset);
            data_offset += 4;
            this.mtu_header.fragment_num = ARUtil.bytes2int(data, data_offset);
            data_offset += 4;
            this.mtu_header.fragment_index = ARUtil.bytes2int(data, data_offset);
            data_offset += 4;
            this.mtu_header.sub_protocol = data[data_offset];
            ++data_offset;
            System.arraycopy(data, data_offset, this.mtu_header.reserve, 0, 3);
            data_offset += 3;
            System.arraycopy(data, data_offset, this.mtu_header.check_sum, 0, 4);
            return this.mtu_header;
        }

        private ARUsbTransfer.HID_HEADER get_hid_header(byte[] data, int offset) {
            this.hid_header.port_index = ARUtil.bytes2short(data, offset);
            int data_offset = offset + 2;
            this.hid_header.header_len = ARUtil.bytes2short(data, data_offset);
            data_offset += 2;
            this.hid_header.date_len = ARUtil.bytes2int(data, data_offset);
            data_offset += 4;
            this.hid_header.status = data[data_offset];
            ++data_offset;
            System.arraycopy(data, data_offset, this.hid_header.reserve, 0, 3);
            return this.hid_header;
        }

        public void run() {
            byte[] read_data = new byte[512];

            while(true) {
                while(true) {
                    int read_len;
                    do {
                        if (!this.bRun) {
                            return;
                        }

                        read_len = ARUsbTransfer.this.mHIDHelper.ReadData(read_data);
                    } while(read_len <= 0);

                    if (read_len < 36) {
                        Log.e(ARUsbTransfer.TAG, String.format("hid read error len(not enough for mtu header):%d", read_len));
                    } else {
                        ARUsbTransfer.MTU_HEADER mheader = this.get_mtu_header(read_data, 0);
                        if (!Arrays.equals(mheader.magic_number, this.magic)) {
                            Log.e(ARUsbTransfer.TAG, String.format("mtu header error %s", ARUtil.bytesToHex(mheader.magic_number)));
                        } else if (mheader.sub_protocol != 1) {
                            Log.e(ARUsbTransfer.TAG, String.format("sub protocol error %d", mheader.sub_protocol));
                        } else if (read_len < 48) {
                            Log.e(ARUsbTransfer.TAG, String.format("hid read error len(not enough for hid header):%d", read_len));
                        } else {
                            if (mheader.fragment_index == 0) {
                                this.mtu_payload_cache = null;
                                this.mtu_payload_cache = new byte[mheader.total_len];
                            }

                            if (this.mtu_payload_cache != null) {
                                System.arraycopy(read_data, 36, this.mtu_payload_cache, mheader.fragment_index * 476, mheader.payload_len);
                                if (mheader.fragment_index + 1 == mheader.fragment_num) {
                                    ARUsbTransfer.HID_HEADER hheader = this.get_hid_header(this.mtu_payload_cache, 0);
                                    switch(hheader.port_index) {
                                        case 0:
                                            byte[] sArray = new byte[hheader.date_len];
                                            System.arraycopy(this.mtu_payload_cache, 12, sArray, 0, hheader.date_len);
                                            String sUpgdLog = new String(sArray);
                                            sUpgdLog = sUpgdLog.trim();
                                            if (!sUpgdLog.isEmpty()) {
                                                ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_UPGRADE_STATUS, sUpgdLog, 0);
                                            }
                                        case 1:
                                        case 2:
                                        case 4:
                                        case 5:
                                        case 6:
                                        case 7:
                                        default:
                                            break;
                                        case 3:
                                            byte[] sArray2 = new byte[hheader.date_len];
                                            System.arraycopy(this.mtu_payload_cache, 12, sArray2, 0, hheader.date_len);
                                            String sUcmdLog = new String(sArray2);
                                            sUcmdLog = sUcmdLog.trim();
                                            if (!sUcmdLog.isEmpty()) {
                                                ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_UCMD_RET, sUcmdLog, 0);
                                            }
                                            break;
                                        case 8:
                                            byte[] sArray3 = new byte[hheader.date_len];
                                            System.arraycopy(this.mtu_payload_cache, 12, sArray3, 0, hheader.date_len);
                                            String sGifoLog = new String(sArray3);
                                            sGifoLog = sGifoLog.trim();
                                            if (!sGifoLog.isEmpty()) {
                                                ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_GIFO_RET, sGifoLog, 0);
                                            }
                                            break;
                                        case 9:
                                            byte[] sArray4 = new byte[hheader.date_len];
                                            System.arraycopy(this.mtu_payload_cache, 12, sArray4, 0, hheader.date_len);
                                            if (sArray4.length == 4) {
                                                int mm = ARUtil.bytes2int(sArray4, 0);
                                                if (mm == 2) {
                                                    ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_HERT_RET, "heart", 0);
                                                }
                                            }
                                            break;
                                        case 10:
                                            byte[] sArray5 = new byte[hheader.date_len];
                                            System.arraycopy(this.mtu_payload_cache, 12, sArray5, 0, hheader.date_len);
                                            if (sArray5.length >= 12) {
                                                byte[] flag = new byte[4];
                                                System.arraycopy(sArray5, 0, flag, 0, 4);
                                                if (Arrays.equals(flag, ARUsbTransfer.this.conf_flag)) {
                                                    int stat = ARUtil.bytes2int(sArray5, 4);
                                                    int len = ARUtil.bytes2int(sArray5, 8);
                                                    if (stat == 0) {
                                                        ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_CONF_RET, "config ok", 0);
                                                    } else {
                                                        ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_CONF_RET, "config error-" + stat, 0);
                                                    }
                                                    continue;
                                                }
                                            }

                                            ARUsbTransfer.this.statusChange(ARUsbTransfer.LOG_MSG_TYPE.HID_CONF_RET, new String(sArray5), 0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private final class HID_HEADER {
        public static final int LENGTH = 12;
        public short port_index;
        public short header_len;
        public int date_len;
        public byte status;
        public byte[] reserve;

        private HID_HEADER() {
            this.reserve = new byte[3];
        }
    }

    private final class MTU_HEADER {
        public static final int LENGTH = 36;
        public final byte[] magic_number;
        public int header_len;
        public int total_len;
        public int payload_len;
        public int fragment_num;
        public int fragment_index;
        public byte sub_protocol;
        public final byte[] reserve;
        public final byte[] check_sum;

        private MTU_HEADER() {
            this.magic_number = new byte[8];
            this.reserve = new byte[3];
            this.check_sum = new byte[4];
        }
    }

    @Keep
    public interface StatusCallback {
        void onStatusChange(ARUsbTransfer.LOG_MSG_TYPE var1, String var2, int var3);
    }

    @Keep
    public static enum LOG_MSG_TYPE {
        UVC_STATUS,
        UVC_ERROR,
        HID_TRANS_STATUS,
        HID_TRANS_PROGRESS,
        HID_TRANS_ERROR,
        HID_UPGRADE_STATUS,
        HID_UCMD_RET,
        FACERECORD_UPDATE,
        FACEREGED_UPDATE,
        HID_HERT_RET,
        HID_OPEN_STATUS,
        HID_GIFO_RET,
        HID_CONF_RET;

        private LOG_MSG_TYPE() {
        }
    }
}
